<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <link href="./css/bootstrap.css" rel="stylesheet">
        <link href="./css/signin.css" rel="stylesheet">
    </head>
    <body>
        <?php session_start(); ?>
        <div class="container">
            <!-- 显示登录表单 -->
            <form class="form-signin" role="form" action="" method="POST">
                <h2 class="form-signin-heading">Mobile Shop</h2>
                <input name="user" type="text" class="form-control" placeholder="用户名" required autofocus>
                <input name="pass" type="password" class="form-control" placeholder="密码" required>

                <label class="checkbox">
                    <input name="remeber" type="checkbox" value="1"> 记住我
                    <a href="index.php" class="btn btn-sm" role="button">随便逛逛</a>
                </label>
                <button name="LoginBtn" class="btn btn-sm btn-primary btn-block" type="submit">登录</button>

            </form>
            <!-- 处理登录 -->
            <?php
            require './user.php';  //包含用户定义
            if (isset($_POST['LoginBtn'])) {
                $ErrMsg = valid_user($_POST['user'], $_POST['pass']);
                if ($ErrMsg) {
                    echo "<div class = \"alert alert-danger\" role = \"alert\">\n";
                    echo $ErrMsg;
                    echo "</div>\n";
                } else {
                    header("Location: index.php");
                }
            }
            ?>
        </div>

    </body>
</html>
